package com.solcoo.merchant.ui.level;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.solcoo.merchant.ApplicationExt;
import com.solcoo.merchant.Constant;
import com.solcoo.merchant.R;
import com.solcoo.merchant.base.BaseActivity;
import com.solcoo.merchant.base.task.TaskHelper;
import com.solcoo.merchant.base.task.TaskHelper.Callback;
import com.solcoo.merchant.base.task.TaskHelper.DefaultCallback;
import com.solcoo.merchant.model.LevelListDO;

public class LevelActivity extends BaseActivity {

	LevelAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.level);
		ListView levelList = (ListView) findViewById(R.id.level_list);
		adapter = new LevelAdapter(this);
		levelList.setAdapter(adapter);
		findViewById(R.id.setting_btn).setVisibility(View.VISIBLE);
	}

	@Override
	protected void onResume() {
		super.onResume();
		TaskHelper.loadView(this,
				Constant.URL.getLevel(ApplicationExt.getUser().yonghum),
				callback, LevelListDO.class);
	}

	private Callback<LevelListDO> callback = new DefaultCallback<LevelListDO>(
			this) {

		@Override
		public void onSuccess(LevelListDO result) {
			adapter.update(result);
		}

	};

	public void settingOnClick(View v) {
		Intent it = new Intent(v.getContext(), AddLevelActivity.class);
		it.putExtra(AddLevelActivity.INTENT_KEY, adapter.getCount());
		v.getContext().startActivity(it);
	}

}
